# __init__.py 为初始化加载文件

from ascript.android.ui import time
# from airscript.intent import Intent 
# from airscript.action import slide
import random
from airscript.action import click
from airscript.node import Selector
from airscript.action import input 
from airscript.ui.dialog import promat
from airscript.system import Media

# Media.talk('在老师你好')


wen_an = ['[比心][比心][比心][比心][比心][比心][比心][比心][比心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心]交朋友 交朋友 交朋友 交朋友.....有粉必回',
'[比心][比心][比心][比心][比心][比心][比心][比心][比心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心]我我我我我交朋友 我我 交朋友。。。。有粉必回',
'[爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心][爱心]互交朋友 交朋友 互赞__有没有']


shuru = False

def tunner(k,v):
    if(k=="__promat"):
        if v == "cancle":
            print('默认文案')
        else:
            wen_an=[v]
            print('点击了确认:输入值为:',v)

dialog =  promat('输入自定义文案?').show(tunner)
shuru = True
fensishu = Selector().id("com.ss.android.ugc.aweme:id/o2d").type("Button").packageName("com.ss.android.ugc.aweme").find()
renshu = int(fensishu.text.replace('万','0000',1))
print("当前直播间人数：", renshu)
 
while shuru and renshu >200 :
    try:
        time.sleep(random.randint(1,3))
        fensishu = Selector().id("com.ss.android.ugc.aweme:id/o2d").type("Button").packageName("com.ss.android.ugc.aweme").find()
        renshu = int(fensishu.text.replace('万','0000',1))
        print("当前直播间人数：",renshu )
        time.sleep(random.randint(1,3))
        b = random.randint(0,len(wen_an)-1)
        pinglun = wen_an[b]
        print(pinglun)
        Selector().id("com.ss.android.ugc.aweme:id/fp9").click().find_all()
        time.sleep(random.randint(2,3))
        input(pinglun)
        time.sleep(1)
        #点击发送
        Selector().id("com.ss.android.ugc.aweme:id/yku").click().find_all()
    except Exception as e:
            print('本次执行失败', e)
            time.sleep(6)
    finally:
        if renshu <200 :
            # 滑动切换直播间
            print('人数太少 切换直播间...')

        print('执行完毕 finally...')

# time.sleep(random.randint(1,3))

# 1.启动抖音
# Intent.run("com.ss.android.ugc.aweme")
# time.sleep(random.randint(2,4))
